<template>
	<gzPageWrapper
		ref="gzPageWrapperRef"
		:styles="{ background: '#f7f8fb' }"
		:up="{ textNoMore: '--暂无更多--', empty: { use: false } }"
		:down="{ use: true, auto: false }"
		:nav="{ use: false }"
		:scroll="{ top: 50, fixed: true }"
		@upCallback="upCallback"
	>
		<template #top>
			<uni-segmented-control class="uni-tab" :current="vdata.tabCurrent" :values="vdata.tabItems" @clickItem="onClickTabItem" styleType="text" activeColor="#00A952"></uni-segmented-control>
		</template>
		<template #default>
			<view>
				<levelRecord :scoreList="vdata.scoreList"/>
			</view>
		</template>
	</gzPageWrapper>
</template>
<script setup>
	import levelRecord from './levelRecord.vue'
	import { ref, reactive } from 'vue'
	import storageManage from '@/util/storageManage.js'
	import {onLoad} from '@dcloudio/uni-app'
	import { $scoreRecord,$assetSelectMonth,$assetSelectQuarter } from '@/http/apiManager.js'
	
	const gzPageWrapperRef = ref()
	
	const vdata = reactive({
		tabItems: ['月度等级', '季度等级', ],
		tabCurrent: 0,
		scoreList: [],	// 福分列表
	})
	const params = reactive({
		state: 0
	})
	
	onLoad(()=>{
		// upCallback(mescroll)
	})
	
	
	
	
	const onClickTabItem = ({ currentIndex }) => {
		if(vdata.tabCurrent == currentIndex) return
		vdata.tabCurrent = currentIndex
		switch (currentIndex){
			case 0:
				params.state = 0
				break
			default:
				params.state = 1
				break;
		}
		gzPageWrapperRef.value.getMescroll().resetUpScroll()
	}
	
	
	/**
	 * 上拉刷新
	 */
	function upCallback(mescroll){
		const { num, size } = mescroll
		const pageNumber = num ? num : 1
		const pageSize = size ? size : 10
		if(params.state == 0){
			console.log('走的这里 月度')
			// 月度
			$assetSelectMonth({ pageNumber, pageSize }).then(({ bizData }) => {
				if(pageNumber == 1) vdata.scoreList = []
				vdata.scoreList = vdata.scoreList.concat(bizData.records)
				mescroll.endSuccess(bizData.records.length,bizData.hasNext)
			}).catch(() => {
				mescroll.endErr()
			})
		}
		if(params.state == 1){
			// 季度
			console.log('走的这里  季度')
			$assetSelectQuarter({ pageNumber, pageSize }).then(({ bizData }) => {
				if(pageNumber == 1) vdata.scoreList = []
				vdata.scoreList = vdata.scoreList.concat(bizData.records)
				mescroll.endSuccess(bizData.records.length,bizData.hasNext)
			}).catch(() => {
				mescroll.endErr()
			})
			
		}
		// $scoreRecord({ pageNumber, pageSize }).then(({ bizData }) => {
		// 	if(pageNumber == 1) vdata.scoreList = []
		// 	vdata.scoreList = vdata.scoreList.concat(bizData.records)
		// 	mescroll.endSuccess(bizData.records.length,bizData.hasNext)
		// }).catch(() => {
		// 	mescroll.endErr()
		// })
	}
</script>

<style lang="less">
	.uni-tab{
		position: fixed;
		top: 0;
		left: 0;
		z-index: 999;
		width: 100%;
	}
	:deep(.segmented-control) {
		background: #fff;
		padding-bottom: 10rpx;
	}
	:deep(.segmented-control){
		background: #fff;
		padding-bottom: 10rpx;
	}
</style>